package yto.freemarker.java8.lambda;

import org.junit.Test;
import yto.freemarker.java8.entity.Employee;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author dongxing
 * @create 2018-06-19 13:23
 **/
public class LambdaDemo01 {

    List<Employee> list = Arrays.asList(new Employee("Zhansgan", 10, 200.0),
            new Employee("lisi", 20, 300.0),
            new Employee("wangwu", 30, 400.0),
            new Employee("zhangliu", 40, 500.0)
    );


    /**
     * 排序，年龄一样，按名字进行排序
     */
    @Test
    public void test1() {
        Collections.sort(list, (e1, e2) -> {
            if (e1.getAge().equals(e2.getAge())) {
                return e1.getName().compareTo(e2.getName());
            } else {
                return e1.getAge().compareTo(e2.getAge());
            }
        });


        for (Employee employee : list) {
            System.out.println(employee);
        }
    }


}
